/*
 * Copyright (C) 2005 Johan Maasing johan at zoom.nu Licensed under the Apache
 * License, Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package nu.zoom.swing.desktop.plugin.portunis;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.Key;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.Date;
import java.util.Enumeration;

/**
 * Wraps a KeyStore class. A thin wrapper around a java.security.KeyStore. Adds
 * a list of listeners for changes to the keystore. Classes implementing this
 * interface should fire a change event when necessary.
 * 
 * @see java.security.KeyStore
 * @version $Revision: 1.1 $
 * @author $Author: johan $
 */
public interface ZoomKeyStore {

	/**
	 * Add a listener for KeyStore events.
	 * 
	 * @param listener
	 *            The listener to add.
	 */
	public void addKeyStoreListener(KeyStoreListener listener);

	/**
	 * Remove a previously registered listener of KeyStore events.
	 * 
	 * @param listener
	 *            The listener to remove.
	 */
	public void removeKeyStoreListener(KeyStoreListener listener);

	/**
	 * @see java.security.KeyStore#aliases()
	 */
	Enumeration aliases() throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#containsAlias(java.lang.String)
	 */
	boolean containsAlias(String alias) throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#deleteEntry(java.lang.String)
	 */
	void deleteEntry(String alias) throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#getCertificate(java.lang.String)
	 */
	Certificate getCertificate(String alias) throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#getCertificateAlias(java.security.cert.Certificate)
	 */
	String getCertificateAlias(Certificate cert) throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#getCertificateChain(java.lang.String)
	 */
	Certificate[] getCertificateChain(String alias) throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#getCreationDate(java.lang.String)
	 */
	Date getCreationDate(String alias) throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#getKey(java.lang.String, char[])
	 */
	Key getKey(String alias, char[] password) throws KeyStoreException,
			NoSuchAlgorithmException, UnrecoverableKeyException;

	/**
	 * @see java.security.KeyStore#getProvider()
	 */
	Provider getProvider();

	/**
	 * @see java.security.KeyStore#getType()
	 */
	String getType();

	/**
	 * @see java.security.KeyStore#isCertificateEntry(java.lang.String)
	 */
	boolean isCertificateEntry(String alias) throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#isKeyEntry(java.lang.String)
	 */
	boolean isKeyEntry(String alias) throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#load(java.io.InputStream, char[])
	 */
	void load(InputStream stream, char[] password)
			throws NoSuchAlgorithmException, CertificateException, IOException;

	/**
	 * @see java.security.KeyStore#setCertificateEntry(java.lang.String,
	 *      java.security.cert.Certificate)
	 */
	void setCertificateEntry(String alias, Certificate cert)
			throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#setKeyEntry(java.lang.String, byte[],
	 *      java.security.cert.Certificate[])
	 */
	void setKeyEntry(String alias, byte[] key, Certificate[] chain)
			throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#setKeyEntry(java.lang.String,
	 *      java.security.Key, char[], java.security.cert.Certificate[])
	 */
	void setKeyEntry(String alias, Key key, char[] password, Certificate[] chain)
			throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#size()
	 */
	int size() throws KeyStoreException;

	/**
	 * @see java.security.KeyStore#store(java.io.OutputStream, char[])
	 */
	void store(OutputStream stream, char[] password) throws KeyStoreException,
			NoSuchAlgorithmException, CertificateException, IOException;
}
